#!/bin/sh

PROG=fetchmail
ARGS="-d 300 -t 60 -a -e 50 --auth password -f /opt/etc/fetchmailrc @LOGGING@"

if [ -z "$1" ] ; then
    case `echo "$0" | /bin/sed 's/^.*\/\(.*\)/\1/g'` in
	S??*) rc="start" ;;
	K??*) rc="stop" ;;
	*) rc="usage" ;;
    esac
else
    rc="$1"
fi

case "$rc" in
    start)
	echo "starting service $PROG"
	
	$PROG $ARGS 2>&1
	;;
    stop)
	echo "stopping service $PROG"
	
	if [ -n "`/opt/bin/pidof $PROG`" ]; then
	    /opt/bin/killall $PROG
	fi
	;;
    restart)
	"$0" stop
	sleep 1
	"$0" start
	;;
    *)
	echo "Usage: $0 (start|stop|restart|usage)"
	;;
esac

